package com.guigu.order.service.impl;

import com.guigu.order.entity.Rule;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.guigu.order.entity.rules.AddressRule;
import com.guigu.order.mapper.RuleMapper;
import com.guigu.order.service.RuleService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.math.BigDecimal;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author TaoLong
 * @since 2021-11-09
 */
@Service
@Transactional
public class RuleServiceImpl extends ServiceImpl<RuleMapper, Rule> implements RuleService {

    @Override
    public String calcFee(AddressRule addressRule) {
        BigDecimal lost = new BigDecimal(addressRule.getTotalWeight()).subtract(new BigDecimal(addressRule.getFirstWeight()));
        lost = lost.setScale(0, BigDecimal.ROUND_DOWN);
        BigDecimal continuedFee = lost.multiply(new BigDecimal(addressRule.getContinuedFee()));
        return continuedFee.add(new BigDecimal(addressRule.getFirstFee())).toString();
    }
}
